#pragma once
#include "XmlConfig.h"

#define DECLARE_XML_CONFIG_LOADER virtual HRESULT TransferConfiguration(XmlConfig::TransferMode mode);

#define BEGIN_XML_CONFIG_LOADER(cls) \
	HRESULT cls::TransferConfiguration(XmlConfig::TransferMode mode) { \
	bool ret; \
	char * clsname = #cls; \
	if (Log) Log->Out("Loading %s for %s\n", _Filename, #cls); \
	ASSERT((ret = _Config.Open(_Filename)) == true); \
	if (ret == false) \
	return E_UNEXPECTED;

#define XML_CONFIG_LOADER_LINK_STRING(var, link) ASSERT(_Config.TransferString(link, var, XML_CONFIG_MAX_VAR_LENGTH, mode)); if (Log) Log->Out("%s(0x%x).%s = '%s' [String]\n", clsname, this, #var, var);
#define XML_CONFIG_LOADER_LINK_INTEGER(var, link) ASSERT(_Config.TransferInteger(link, &var, mode)); if (Log) Log->Out("%s(0x%x).%s = %d [Integer]\n", clsname, this, #var, var);

#define END_XML_CONFIG_LOADER return S_OK; }
#define DECLARE_XML_STRING(x) char x[XML_CONFIG_MAX_VAR_LENGTH];
#define DECLARE_XML_INTEGER(x) int x;

class XmlConfigLoader
{
public:
	XmlConfigLoader(const char * filename);
	~XmlConfigLoader(void);

	HRESULT ReadConfiguration(void);
	HRESULT WriteConfiguration(void);

	virtual HRESULT TransferConfiguration(XmlConfig::TransferMode mode) = 0;

protected:
	char _Filename[MAX_STRING_LENGTH];
	XmlConfig _Config;
};

